use organisation
//Data manipulation
encode RegisteredStatus, gen(regstat)
recode regstat 1=0
recode regstat 2=1
label define regstat 0 "Dead" 1 "Live", replace
label values regstat regstat
encode OwnershipClassification, gen (ownership)
//Generating years that the firms have died and were created//
//Note that some co-ops have different codings for the dates//
//This is the reason why more code for different dates is present//
gen incorpdate = date(IncorporationDate,"MDY")
format %tdMonth_DD,_CCYY incorpdate
gen yrcreated1=year(incorpdate)
recode yrcreated1 .=0
gen incorpdate1 = date(IncorporationDate,"DMY") if yrcreated1 == 0
format %tdMonth_DD,_CCYY incorpdate1
gen yrcreated2=year(incorpdate1)
recode yrcreated2 .=0
gen yrcreated=yrcreated1+yrcreated2
gen yrdied=year(DissolvedDate)
recode yrdied .=2019
gen diedonyear = yrdied-yrcreated + 1
//Cooperatvies dropped due to colinnearity, employee trust dropped due to insufficiant sample size//
drop if ownership == 1
drop if ownership == 4
recode ownership 2=0 3=1 5=2 6=3 7=4 8=5 9=6
label define ownership 0 "Community of Interest" 1 "Consumer" 2 "Enterprise" 3 "Multi-stakeholder" 4 "Self-employed" 5 "Tenants" 6 "Worker", replace
label values ownership ownership
label variable yrcreated "Year created"
label variable diedonyear "Died on year"
label variable regstat "Registation status"
save merged_cleaned_1, replace
keep if yrcreated >= 2011
keep if yrcreated <=2014
recode regstat 0 = 1 if yrdied == 2019
keep ownership diedonyear regstat yrcreated
save sec3cleaned, replace
//Data analysis//
use sec3cleaned
set scheme s1mono
forvalues i = 1/4 {
	tab ownership if yrcreated == 201`i'
	}
stset diedonyear, failure(regstat==0)
//Models//
forvalues i = 1/4 {
	stcox ib1.ownership if yrcreated == 201`i'
	est store model`i'
	estat phtest
	}

//Making tables and graphs//
esttab model1 model2 model3 model4 using survival1.rtf, ///
obslast se(3) eform nonumber title(Table 6. Cox porportional hazrds model on different co-op survival) ///
mtitles("2011" "2012" "2013" "2014") replace

est restore model1
sts graph, hazard noboundary by(ownership) ci, if ownership ==1 & yrcreated == 2011| ownership==6 & yrcreated == 2011,  tmax(6) saving(1, replace)
sts graph, by(ownership) ci, if ownership == 1 & yrcreated == 2011| ownership == 6 & yrcreated == 2011, tmax(6) saving(2, replace)
gr combine 1.gph 2.gph
sts list, survival by(ownership), if yrcreated == 2011
est restore model2
sts graph, hazard noboundary by(ownership) ci, if ownership ==1 & yrcreated == 2012 | ownership==6 & yrcreated == 2012,  tmax(6) saving(3, replace)
sts graph, by(ownership) ci, if ownership == 1 & yrcreated == 2012| ownership == 6 & yrcreated == 2012, tmax(6) saving(4, replace)
gr combine 3.gph 4.gph
sts list, survival by(ownership), if yrcreated == 2012
est restore model4
sts graph, hazard noboundary by(ownership) ci, if ownership ==1 & yrcreated == 2014| ownership==6 & yrcreated == 2014,  tmax(6) saving(7, replace)
sts graph, by(ownership) ci, if ownership == 1 & yrcreated == 2014| ownership == 6 & yrcreated == 2014, tmax(6) saving(8, replace)
gr combine 7.gph 8.gph
sts list, survival by(ownership), if yrcreated == 2014

